<?php
	/* Description: This file is used to add sub sub category. */
	#########IncludeFiles####################################################################################
	include_once '../inc/config.php';
	include_once("../inc/bootstrape.php");
    require_once _SITE_PATH_.'classes/Master/Master.php';
    require_once _SITE_PATH_.'classes/Product/Product.php';

	require_once _SITE_PATH_.'classes/CommonUtility/CommonUtility.php';

	if( $_POST['submit']=='Submit'){   
		
		$parms['name'] = $_POST['name'];
		$parms['entity_type'] = $_POST['entity_type'];
		
		if($parms['entity_type'] == 1){
			$parms['entity_id'] = $_POST['service'];
		}else if($parms['entity_type'] == 2){
			$parms['entity_id'] = $_POST['product'];
		}

        $parms['discount'] = $_POST['discount'];
        $parms['discount_type'] = $_POST['discount_type'];
        $parms['start_date'] = $_POST['start_date'];
        $parms['end_date'] = $_POST['end_date'];
		$parms['added'] = date("Y-m-d");
	 	
        // upload and create thumb of the image //
        if( !empty( $_FILES['deal_image'] ) ){
            $filename  = 'deal_image';     //  this is name of the control you are using in html form         
            $module='deals';
            $uploadedfile = CommonUtility::uploadNcreateThumb($filename, $module, false);
            if( $uploadedfile!= -1 )    {
                $parms['banner'] = $uploadedfile;
            }        
        }
        			    
		if( CommonUtility::insertData($parms, 'deals')) {        
			header("Location: deal_mng.php?msg=1164");            
			exit;
		}
		$err = 1165;    
	}
	
	$products = array();
	$products = Product::getActiveProducts();
	
	$services = array();
	$services = Master::getActiveServices();
	
	$errMsg = $err;
	$_tplName = 'deals/deal_add.tpl';
	$_title = 'Add Deal';

    $_extraJS[] = _SITE_URL_ . 'lib/calender/js/cal.js';
	require_once _ADMIN_TPL_MAIN_;
?>